package com.netease.rmi.client;

import com.netease.rmi.server.UserHandlerInterface;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * @author bjweitingting
 * @description
 * @date 2018/8/22
 **/
public class Main {
    public static void main(String[] args) {
        try {
            //Naming.lookup(...)获取该远程对象的引用
            System.out.println(Naming.lookup("user").getClass().toString());
            UserHandlerInterface handler = (UserHandlerInterface) Naming.lookup("user");
            System.out.println(handler.hashCode());
            int count = handler.getUserCount();
            String name = handler.getUserName(1);
            System.out.println("name: " + name);
            System.out.println("count: " + count);
            System.out.println("user: " + handler.getUserByName("lmy86263") + "_age=" + handler.getUserByName("lmy86263").getAge());
        } catch (NotBoundException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public static void foo(Object obj) {
        int sum = 0;
        for (int i = 0; i < 200; i++) {
            sum += i;
        }
    }
}
